package com.vieewer.btdemo.view.wifi;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.vieewer.btdemo.R;

import java.util.List;

/**
 * Created by yaoshuai on 2017/5/15.
 */

public class PathAdapter extends RecyclerView.Adapter<PathAdapter.MyViewHolder>{
    private Context context;
    private List<String> mData;

    /**定义接口*/
    public interface OnItemClickListener {
        void OnItemClick(View view, int position);
    }

    public OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public PathAdapter(Context context, List<String> mData){
        super();
        this.context = context;
        this.mData = mData;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
        View view= layoutInflater.inflate(R.layout.recive_picture_path_item,parent,false);
        MyViewHolder myViewHolder = new MyViewHolder(view);
        return myViewHolder;
    }

    //    @Override
//    public void onBindViewHolder(final MyViewHolder holder, final int position) {
//        holder.textView.setText(mData.get(position));
//    }
    @Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {
        holder.textView.setText(mData.get(position));

//        if(onItemClickListener != null){
            holder.textView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //使用接口回调的方法将参数传递出来
//                    onItemClickListener.OnItemClick(holder.textView,position);

                    Intent intent = new Intent();
                    intent.setAction(Intent.ACTION_VIEW);
                    intent.setDataAndType(Uri.parse("file://" + mData.get(position)), "image/*");
                    context.startActivity(intent);
                    Log.i("tag","111111111111");
                }
            });
//        }

    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder{
        private TextView textView;
        public MyViewHolder(View itemView){
            super(itemView);
            textView = (TextView) itemView.findViewById(R.id.item_text);
        }
    }
}

